package com.hfjy.jython.scala.demo

import com.hfjy.jython.scala.demo.ml.Demo1

object WordCount {
  def main(args: Array[String]): Unit = {
//    val conf=new SparkConf().setAppName("wordcount")
//    val sc=new SparkContext(conf)
    //val input=sc.textFile("/root/test.txt")
//    val input=sc.textFile("d:/2.txt")
//    val lines=input.flatMap(line=>line.split(" "))
//    val count=lines.map(word=>(word,1)).reduceByKey{case (x,y)=>x+y}
//    val output=count.saveAsTextFile("d:/tt.txt")
    //arr()
//    arrayBuffer()

//    map1()
//      map2()
//    fun()

//      var res=getCard[String]("hello,world")
//    println(res)
    val demo = new Demo1
    demo.d1()
  }
  def arr()={
    val  a = new Array[String](10)
    a(0)="php"
    a(2)="python"
    a(4)="java"
    for (i<- a){
      println(i)
    }
    val b=Array("golang","lua")
    b(1)="scala"

    val c=Array("javascript",22)

  }
  def arrayBuffer()={
    import scala.collection.mutable.ArrayBuffer
    val b=ArrayBuffer[Int]()
    b+=1
    b+=(2,3,4)
    b.insert(4,2)
    //在第五个后面添加2,4,5
    b.insert(5,2,4,5)
    b.remove(1)
    //从第一个开始移除三个元素
    b.remove(1,3)
    for (i <- b){
      println(i)
    }
    println("-------------------")
    println(b.trimEnd(2))
    val c=b.toArray
    for (i<-c){
      println(i)
    }
    val d=c.toBuffer
    for (i<-d){
      println(i)
    }
    println(d.mkString(","))
    val e=d.filter(_%2==0)
    println(e.mkString(","))

  }
  def map1()={
    val ages=Map("one"->"php","two"->"java")
    import scala.collection.mutable.Map
    val a=Map("one1"->"golang","two1"->"javascript")
    a++=ages
    for ((k,v)<-a){
      println(k)
      println(v)
    }
    println("------------------")
    for (i<-a.keys){
      println(i)
    }
    println("------------------")
    for (i<-a.values){
      println(i)
    }
    a("three")="nodejs"
    println("------------------")
    //移除元素,键为one1的元素
    a-="one1"
    for ((k,v)<-a){
      println(k,v)
    }
    println("------------------")
    //移除不可变元素
    val b=ages-"one"
    for ((k,v)<-b){
      println(k,v)
    }
  }
  def map2()={
    //可排序列的map
    import scala.collection.immutable.SortedMap
    val a=SortedMap("2"->"golang","1"->"php")
    for ((k,v)<-a){
      println(k,v)
    }
    println("--------------------")
    //hashmap
    import scala.collection.mutable.HashMap
    val b=new HashMap[String,Int]
    b.put("java",1)
    b.put("golang",1)
    for ((k,v)<-b){
      println(k,v)
    }
  }
  def fun()={
    def sayHello(name:String): Unit ={
      println("ok"+name)
    }
    val say=sayHello _
    say("jython")
    val say2=(name:String)=>println("hi"+ name)
    say2("jython")
  }
  def bounds()={

  }
  //泛型函数
  def getCard[T](content:T)={
    if(content.isInstanceOf[Int])"card:001,"+content
    else if (content.isInstanceOf[String])"card:this is your card"+content
    else "card"+content
  }
}

